<template>
	<view class="">
		<quill-editor disabled v-model="describe" class="ql-editor" />
		<view class="card-list">
			<view class="card-item" v-for="(item,index) in list" :key="index">
				<view class="option">
					<radio :checked="item.isCheck" @click="itemCheck(index)" />
					<image v-if="item.abilityIcon" :src="item.abilityIcon" mode=""></image>
					<image v-else src="../../../static/logo.png" mode=""></image>
				</view>
				<view class="detail">
					<view class="top">
						<text>{{item.abilityName}}</text>
						<button @click="jumpDetail(item)">查看详情</button>
					</view>
				</view>
			</view>
		</view>
		<view class="footer">
			<view class="">
				<radio :checked="isAll" @click="checkAll" />
				<text>全选</text>
			</view>
			<button :style="{background:(abilityId.length?'#0B4E9E':'#CCCCCC')}" @click="jumpApply">我有需求</button>
		</view>
	</view>
</template>

<script>
	import api from 'api/modules/energize.js';
	export default {
		name: 'Attract',
	
		onLoad(params) {
			api.getFrontDetail({
				associationServiceId: 6
			}).then(res => {
				this.describe = res.data.serviceContent
				this.getData()
			})
		},
		data() {
			return {
				isAll: false,
				describe: "",
				list: [],
				abilityId: []
			}
		},

		methods: {
			setAbilityId() {
				let list = []
				let arr = this.list.filter((item) => {
					return item.isCheck
				})
				arr.forEach(item => {
					list.push(item.abilityId)
				})
				this.abilityId = list
				console.log(this.abilityId);
			},
			getData() {
				api.getFrontList().then(res => {
					res.data.forEach(item => {
						item.isCheck = false
					})
					this.list = res.data
				})
			},
			itemCheck(index) {
				this.list[index].isCheck = !this.list[index].isCheck
				this.setAbilityId()
			},
			checkAll() {
				this.isAll = !this.isAll
				this.list.forEach(item => {
					item.isCheck = this.isAll ? true : false
				})
				this.setAbilityId()
			},
			jumpDetail(item) {
				uni.navigateTo({
					url: '/pages/views/energize/Detail',
					success: function(res) {
						// 通过eventChannel向被打开页面传送数据
						res.eventChannel.emit('someEvent', {
							data: item
						})
					}
				})
			},
			jumpApply() {
				uni.navigateTo({
					url: `/pages/views/energize/Apply?abilityId=[${this.abilityId}]`
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	page {
		background-color: #F6F6F6;
		padding: 33rpx 24rpx;
		box-sizing: border-box;

		.ql-editor {
			background-image: url(../../../static/energize-bgc.jpg);
			background-size: contain;
			background-repeat: repeat;
			
		}

		/deep/.uni-radio-input {
			width: 32rpx;
			height: 32rpx;
		}

		/deep/.uni-radio-input-checked {
			background-color: #108EE9 !important;
			border-color: #108EE9 !important;

			&::before {
				font-size: 28rpx !important;
			}
		}

		.card-list {
			margin-top: 20rpx;
			margin-bottom: 110rpx;
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;

			.card-item {
				max-width: 339rpx;
				min-width: 339rpx;
				display: flex;
				justify-content: space-between;
				background-color: #fff;
				padding: 37rpx 24rpx;
				box-sizing: border-box;
				margin-top: 20rpx;
				border-radius: 8rpx;

				.option {
					display: flex;
					// min-width: 30%;
					margin-right: 10rpx;

					image {
						margin-left: 5rpx;
						min-width: 88rpx;
						max-width: 88rpx;
						height: 88rpx;
					}
				}

				.detail {
					flex: auto;
					position: relative;
					top: -12rpx;

					.top {
						text {
							font-size: 32rpx;
							// font-weight: 600;
							display: inline-block;
							width: 148rpx;
							overflow: hidden; //超出的文本隐藏
							text-overflow: ellipsis; //溢出用省略号显示
							white-space: nowrap; //溢出不换行
						}

						button {
							line-height: 50rpx;
							height: 50rpx;
							display: inline-block;
							padding: 0 20rpx;
							color: #fff;
							margin: 0;
							background-color: #0B4E9E;
							border-radius: 8rpx;
							font-size: 24rpx;

						}
					}

					.describe {

						font-size: 28rpx;
						color: #666;
						margin-top: 22rpx;
						text-overflow: -o-ellipsis-lastline;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
					}

				}
			}
		}

		.footer {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 24rpx;
			box-sizing: border-box;
			width: 100vw;
			height: 128rpx;
			background-color: #fff;
			position: fixed;
			border-top: 1rpx solid #f6f6f6;
			left: 0;
			bottom: 0;

			text {
				font-size: 28rpx;
				margin-left: 10rpx;
				position: relative;
				top: 5rpx;
			}

			button {
				margin: 0;
				width: 480rpx;
				line-height: 80rpx;
				height: 80rpx;
				color: #fff;
				border-radius: 40rpx;
				font-size: 28rpx;
			}

		}
	}
</style>
